package org.example.ruoxing_admin_springboot3.service.user;

import jakarta.annotation.Resource;
import org.example.ruoxing_admin_springboot3.dao.UserInfoDao;
import org.example.ruoxing_admin_springboot3.exceptionHandleUtils.ExceptionHandleUtils;
import org.example.ruoxing_admin_springboot3.httpResponseResult.ResponseResult;
import org.example.ruoxing_admin_springboot3.mapper.UserInfoMapper;
import org.springframework.stereotype.Service;
@Service
public class UserLogOutService {
    @Resource
    private UserInfoMapper userInfoMapper;
    /**
     * @description 用户退出登陆的方法
     * @author 莫若省
     * @createTime 2024/5/6
     */
    public ResponseResult<Object> userLogOut(String token) {
        try{
            //通过解析token获取用户信息
            UserInfoDao userInfoDao = userInfoMapper.getUserInfoByToken(token);
            //更新用户的token为空
            userInfoDao.setUserCurrentToken(null);
            //更新用户信息
            userInfoMapper.updateUserTokenByUserId(userInfoDao);
            return ResponseResult.SUCCESS();
        }catch( Exception e){
            ExceptionHandleUtils.reportException(e, "用户退出登陆失败!");
            return ResponseResult.ERROR();
        }
    }
}
